package com.shilan.dllo.wangyi.factory;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.shilan.dllo.wangyi.fragment.HeadLineFragment;
import com.shilan.dllo.wangyi.fragment.NewsFragment;

/**
 * Created by dllo on 15/10/23.
 */
public class FragmentFactory {

    private  static SparseArray<Fragment> fragmentMap = new SparseArray<>();

//    private  static  final  String[] urls = {
//            "http://c.3g.163.com/nc/article/list/T1348648517839/0-20.html",
//            "http://c.3g.163.com/nc/article/list/T1348649079062/0-20.html"
//    };


    public static  Fragment createFragment(int position){
        Fragment f = fragmentMap.get(position);
        if(f == null){
            switch (position){
                case 0:
                    f = new HeadLineFragment();
                    break;
                case 1:
                    f =new HeadLineFragment();
                    break;
                case  2:
                    f = new HeadLineFragment();
                case 3:
                    f = new HeadLineFragment();
                    break;

                default:
                    //默认创建的是头条的布局
                    f = new HeadLineFragment();
                    Bundle args = new Bundle();
                    args.putInt(NewsFragment.ARGS_POSITION,position);
                    //args.putInt("url" , urls[position]);
                    f.setArguments(args);
                    break;
            }
            fragmentMap.put(position,f);
        }
        return f;
    }
}
